package br.com.mmm.javacenter.framework.view.taglib.helper;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.tagext.JspFragment;

import br.com.mmm.javacenter.framework.annotations.RenderComponent;

@RenderComponent({
	Boolean.class,
	boolean.class
})
public class InputBoolean extends Input {

	public InputBoolean() {
	
	}
	public InputBoolean(JspContext context, JspFragment fragment) {
		super(context, fragment);
	}

	public boolean beforeInput() throws IOException {
		writer.write("<input ");
		writer.write(getAtributo("type", "checkbox"));
		writer.write(getAtributo("name", getName() + "_check"));
		writer.write(getAtributo("id", getId() + "_check"));
		writer.write(getAtributo("class", "inputBoolean"));
		writer.write(getAtributo("nameHidden", getName()));
		if(getValue() != null){
			writer.write(((Boolean) getValue())?getAtributo("checked", "checked"):"");
		}
		writer.write("/>");
		writer.write("<input ");
		writer.write(getAtributo("type", "hidden"));
		writer.write(getAtributo("name", getName()));
		writer.write(getAtributo("id", getId()));
		if(getValue() != null){
			writer.write(getAtributo("value", (Boolean) getValue()?"true":"false"));
		}else{
			writer.write(getAtributo("value", "false"));
		}
		writer.write("/>");
		return false;
	}
}
